<template>
  <footer class="footer" v-show="list.length > 0">
    <!-- This should be `0 items left` by default -->
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong> item left</span
    >
    <!-- Remove this if you don't implement routing -->
    <ul class="filters">
      <li>
        <a
          :class="{ selected: type === 'all' }"
          @click.prevent="changeType('all')"
          href="#/"
          >All</a
        >
      </li>
      <li>
        <a
          href="#/active"
          :class="{ selected: type === 'active' }"
          @click.prevent="changeType('active')"
          >Active</a
        >
      </li>
      <li>
        <a
          href="#/completed"
          :class="{ selected: type === 'completed' }"
          @click.prevent="changeType('completed')"
          >Completed</a
        >
      </li>
    </ul>
    <!-- Hidden if no completed items are left ↓ -->
    <button class="clear-completed" v-show="isShow" @click="clear">
      Clear completed
    </button>
  </footer>
</template>

<script>
import { mapGetters, mapState } from 'vuex'
export default {
  computed: {
    ...mapState('todos', ['list', 'type']),
    ...mapGetters('todos', ['isShow', 'leftCount']),
  },
  methods: {
    clear() {
      this.$store.commit('todos/clear')
    },
    changeType(type) {
      this.$store.commit('todos/changeType', type)
    },
  },
}
</script>

<style></style>
